home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2602 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  53 lines

  1. Path: news.informatik.uni-stuttgart.de!news
  2. From: Gerhard Muth <muth>
  3. Newsgroups: comp.lang.c++
  4. Subject: using const for structs?
  5. Date: 18 Jan 1996 18:23:08 GMT
  6. Organization: IPVR, University of Stuttgart, Germany
  7. Message-ID: <4dm36c$c1h@zdi.informatik.uni-stuttgart.de>
  8. NNTP-Posting-Host: bronto.informatik.uni-stuttgart.de
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.05 9000/725)
  13. X-URL: news:comp.lang.c++
  14.  
  15. // * Compiler-Problems with const!!
  16. // 
  17. // The example is copied and modified from:
  18. //     Practical C++ Programming,
  19. //     Steve Oualline,
  20. //     O'Reilly & Associates Inc.
  21. //     ISBN 1-56592-139
  22. //     Chapter 10, The C++ Preprocessor
  23. //     #define versus const
  24. //     (Page 156)
  25. //     
  26. // If i try to compile it on a HP 700 with
  27. // $ CC const_struct.C
  28. // i get the following error message:
  29. // CC: "const_struct.C", line 35: error: cannot make a box (1284)
  30. //
  31. // I think, that i have to write a 2-parameter constructor,
  32. // but the book does not tell anything about that. It just says:
  33. //
  34. //     "The #define directive is limited to defining simple
  35. //      constants. The const statement can define almost any
  36. //      type of C++ constant including things such as
  37. //      structure classes."
  38. //
  39. // Question: Is the book wrong or is the compiler just bad?
  40. //
  41. // Gerhard.Muth@rus.uni-stuttgart.de
  42. //
  43.  
  44. struct box {
  45.     float width, heigth; // float was int before
  46. };
  47.  
  48. const box blue_box();
  49. const box pink_box(1.0, 4.5); // this is line 35
  50.  
  51. void main(void) {}
  52.  
  53.